package com.rzl.expense.quartz.task;


import com.rzl.expense.agent.DataAgentService;
import com.rzl.expense.expense.domain.ElePayment;
import com.rzl.expense.expense.domain.EleSiteCode;
import com.rzl.expense.expense.service.IElePaymentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 报账点缴费信息
 *
 * @author admin
 * @date 2023/08/09
 */
@Slf4j
@Component("EleSiteCodeTask")
public class EleSiteCodeTask {
    @Autowired
    private DataAgentService dataAgentService;

    @Autowired
    private IElePaymentService elePaymentService;


    /**
     * 集团用户同步
     */
    public void run(Integer index) {
        log.info("获取集团用户数据..........");
        // 执行sql

        int size;
        // limit起始位置
        int startIndex = 0;
        if(index!=null){
            startIndex=index;
        }
        // limit大小
        int limit = 1000;

        do {
            List<EleSiteCode> list = (List<EleSiteCode>) dataAgentService.getData(RuleSqlAdapter.getSiteCode( startIndex, limit), EleSiteCode.class);
            log.info("获取集团用户数据：{}条", list.size());
            list.forEach(simIntegratedInfo -> {
                try {
                    list.forEach(twrRentCtl -> {
                        elePaymentService.insertEleSiteCode(twrRentCtl);
                    });
                } catch (Exception e) {
//
                }
            });

//            elePaymentService.batchEleSiteCode(list);
            size = list.size();
            startIndex = startIndex + limit;
        } while (size >= limit);

        log.info("数据操作成功");
    }
}
